package ling.common.domain.entity;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModelProperty;
import ling.common.DataUtil;
import lombok.var;

import java.lang.reflect.Array;
import java.util.Date;

public interface ISimpleApproval {


    /** 0草稿,1审批中,100通过,101驳回
     *
     * @param st
     * @param remark
     * @param loginName
     */
    default void approval(Integer st, String remark,String loginName) {
        if (st != null)
            setStatus(st);
        if (loginName == null)
            loginName = SecurityUtils.getUsername();
        if(remark==null&&getStatus()==1)
            remark="审批提交";
        var arr = new Object[4];
        arr[0] = DateUtil.format(new Date(), "yyyy-MM-DD hh:mm:ss");
        arr[1] = loginName;
        arr[2] = getStatus();
        arr[3] = remark;
        var appendJson = DataUtil.toJson(arr);
        if (StringUtils.isBlank(getApprovalRecord()))
            setApprovalRecord(appendJson);
        else
            setApprovalRecord(appendJson + "," + getApprovalRecord());
    }
    default void approval(boolean isPass,String remark,String loginName) {
        if(getStatus()>=100)
            throw new IllegalArgumentException("流程已完结");

        if (isPass)
            setStatus(100);
        else
            setStatus(101);
        approval(null,remark,loginName);
//        if(loginName==null)
//            loginName=SecurityUtils.getUsername();
//        var json = getApprovalRecord();
//        var arr = new Object[4];
//        arr[0] = DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss");
//        arr[1] = loginName;
//        arr[2] = getStatus();
//        arr[3] = remark;
//        var appendJson = DataUtil.toJson(arr);
//        if (StringUtils.isBlank(getApprovalRecord()))
//            setApprovalRecord(appendJson);
//        else
//            setApprovalRecord(appendJson+","+getApprovalRecord());
    }
//    Integer status;
//    String approvalRecord;
    /** 0草稿,1审批中,100通过,101驳回
     *
     * @return
     */
    Integer getStatus();
    void setStatus(Integer st);
    /**
     * 审批记录json[{时间，人员，结果，备注}]
     */

    String getApprovalRecord();

    void setApprovalRecord(String record);
}
